package com.iflytek.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类，需要实现WebMvcConfigurer接口
 * 类上方的@Configuration注解表示这是一个配置类
 */
@Configuration
public class MVCConfig implements WebMvcConfigurer  {

	//添加CORS许可，解决跨域问题
	@Override
	public void addCorsMappings(CorsRegistry registry) {
			registry.addMapping("/api/**")  //匹配api下所有路径
			.allowedOrigins("http://localhost:8084", "http://127.0.0.1:8084")   //允许的源域
			.allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")   //允许使用哪些方式访问
			.allowCredentials(true)
			.maxAge(3600)
			.allowedHeaders("*");
	}
	
	
	
	

//    public void addInterceptors(InterceptorRegistry registry){
//    	registry.addInterceptor(new FirstInterceptor())      //添加拦截器到拦截器链
//                .addPathPatterns("/**")			     //指定该拦截器拦截哪些访问
//                .excludePathPatterns("/login")               //排除部分访问路径不拦截
//                .excludePathPatterns("/css/**")
//                .excludePathPatterns("/fonts/**")
//                .excludePathPatterns("/images/**")
//                .excludePathPatterns("/js/**");
//    	
//    	
////    	registry.addInterceptor(new LoginInterceptor())      //添加拦截器到拦截器链
////		        .addPathPatterns("/**")			     //指定该拦截器拦截哪些访问
////		        .excludePathPatterns("/admin/login")               //排除部分访问路径不拦截
////		        .excludePathPatterns("/css/**")
////		        .excludePathPatterns("/fonts/**")
////		        .excludePathPatterns("/images/**")
////		        .excludePathPatterns("/js/**");
//    	
//    }
}
